
R3F_FNCT_WhoIs = {
	private ["_nick","_slot"];
   	_nick = _this select 0;
	if ((typeName _nick != "STRING") || (_nick == "")) exitWith {};
	_slot = objNull;
	{	if (_nick == (name _x)) exitwith {_slot = _x;};
	} foreach playableUnits;
	_slot;
};

if !(isServer && isDedicated) then {
	R3F_FNCT_MessageCrossroad = {
		private ["_side","_txt","_autority"];
		_side = _this select 0;
		if (typeName _side != "SIDE") exitWith {};
		_autority = _this select 1;
		_txt = _this select 2;
		if ((typeName _autority == "STRING") && (_autority != "") && (typeName _txt == "STRING") && (_txt != "")) then {
			if ((typeName _autority == "HQ") || (_autority == "Airbase")) then {
				[[_side,_autority],nil,rSIDECHAT,_txt] call RE;
			};
		};
	};
	R3F_FNCT_MessageHint = {
		private "_txt";
		_txt = _this select 0;
		if ((typeName _txt == "STRING") && (_txt != "")) then {
			[nil,nil,rHINT,_txt] call RE;
		};
	};
	R3F_FNCT_MessageHint_One = {
		private ["_nick","_txt","_slot","_message","_code"];
		_nick = _this select 0;
		if ((typeName _nick != "STRING") || (_nick == "")) exitWith {};
		_txt = _this select 1;
		if ((typeName _txt != "STRING") || (_txt == "")) exitWith {};
		_slot = [_nick] call R3F_FNCT_WhoIs;
		if !(isPlayer _slot) exitWith {};
		_message = format ["hint ""%1"";",_txt];
		_code = compile _message;
		[ACV_BROADCAST_TO_ONE,_code,objNull,_slot] call ACV_FNCT_BroadcastCode;
	};
	R3F_FNCT_Kitu = {
		private ["_side","_item","_pos","_radius","_array","_class"];
		_side = _this select 0;
		if (typeName _side != "SIDE") exitWith {};
		_item = _this select 1;
		if (isNil "_item") exitWith {};
		_pos = [_item] call R3F_FNCT_GetPos;
		if (count _pos == 0) exitWith {};
		_radius = _this select 2;
		if (typeName _radius != "SCALAR") exitWith {};
		_class = _this select 3;
		if (typeName _class != "ARRAY") exitWith {};
		_array = nearestObjects [_pos,_class,_radius];
		if (count _array > 0) then {
			{	if (((_x isKindOf "LandVehicle") || (_x isKindOf "Air") || (_x isKindOf "Ship")) && (count (crew _x) > 0) && (side _x == _side)) then {
					{	_vehicle = vehicle _x;
						_x action ["getOut",_vehicle];
						_x setdamage 1;
						if (damage _vehicle < 1) then {_vehicle setdamage 1;};
					} forEach (crew _x);
				};
				if (!(isPlayer _x) && (alive _x) && (side _x == _side)) then {_x setdamage 1;};
			} forEach _array;
		};
	};
	R3F_FNCT_BoxLocal = {
		private ["_item","_pos","_array","_count","_i","_box"];
		if (count _this > 0) then {
			_item = _this select 0;
			if (isNil "_item") exitWith {};
			_pos = [_item] call R3F_FNCT_GetPos;
			if (count _pos == 0) exitWith {};
		} else {
			_pos = position player;
		};
		if (count _pos == 0) exitWith {};
		if (count _this > 1) then {
			_array = _this select 1;
		} else {
			_array = ["R3F_WeaponBox_full","Box_NATO_WpsSpecial_F","Box_NATO_Ammo_F"];
		};
		_count = count _array;
		for [{_i = 0},{_i < _count},{_i = _i + 1}] do {
			_box = _array select _i;
			_box createVehicleLocal _pos;
		};
		sleep 300;
		for [{_i = 0},{_i < _count},{_i = _i + 1}] do {
			_box = _array select _i;
			deleteVehicle _box;
		};
	};
};

if (isServer) then {
	R3F_FNCT_Cleaner = {
		private ["_item","_pos","_radius","_class","_distvisible","_array","_ar"];
		_item = _this select 0;
		if (isNil "_item") exitWith {};
		_pos = [_item] call R3F_FNCT_GetPos;
		if (count _pos == 0) exitWith {};
		_radius = _this select 1;
		if (typeName _radius != "SCALAR") exitWith {};
		_class = _this select 2;
		if (typeName _class != "ARRAY") exitWith {};
		_distvisible = _this select 3;
		if (typeName _distvisible != "SCALAR") exitWith {};
		if (_distvisible < 1) then {_distvisible = 1;};
		_array = nearestObjects [_pos,_class,_radius];
		if (count _array > 0) then {
			_ar = [_array,{(!(alive _x) && ([_x,_distvisible] call R3F_FNCT_IsObject_Visible))}] call BIS_fnc_conditionalSelect;
		};
		if (count _ar > 0) then {
			{deleteVehicle _x;} foreach _ar;
			sleep 5;
		};
		{if ((count units _x) == 0) then {deletegroup _x;};} foreach allgroups;
	};
	R3F_FNCT_Regroup = {
		private ["_group","_array","_units"];
		_group = _this select 0;
		if (typeName _group != "GROUP") exitWith {};
		_array = _this select 1;
		if (typeName _array != "ARRAY") exitWith {};
		{	if (typeName _x == "GROUP") then {
				_units = units _x;
				{[_x] joinSilent _group;} forEach _units;
			};
		} forEach _array;
	};
};

R3F_FNCT_PointInShape = {
	private ["_result","_point","_shape","_angle","_rectangle","_center","_dir","_corrected_angle","_cx","_cy"];
	diag_log format["R3F_FNCT_PointInShape %1",_this];
	_result = false;
	_point = _this select 0;
	_shape = _this select 1;
	_center = (_shape select 0);
	_size = (if (typename (_shape select 1) == typename []) then { (_shape select 1) } else { [(_shape select 1),(_shape select 1)] });
	_angle = (if (count _shape < 3) then { 0 } else { _shape select 2 });
	_rectangle = (if (count _shape < 4) then { false } else { _shape select 3 });
	_dist = (_point distance _center);
	_dir = ((_point select 0) - (_center select 0)) atan2 ((_point select 1) - (_center select 1));
	if (_dir < 0) then {_dir = _dir + 360};
	_dir = _dir - 90;
	_corrected_angle = _dir - _angle;
	_cx = _dist * (cos _corrected_angle);
	_cy = _dist * (sin _corrected_angle);
	if (_rectangle) then {
			_result = ((abs(_cx) <= (_size select 0)) && (abs(_cy) <= (_size select 1)));
	} else {
		_dist = (_point distance _center);
		if ((_size select 0) == (_size select 1)) then {
			_result = (_dist <= (_size select 0));
		} else {
			_cx = (((_cx) ^ 2) / ((_size select 0) ^ 2));
			_cx = (((_cy) ^ 2) / ((_size select 1) ^ 2));
			_result = (_cx + _cy) <= 1;
		};
	};
	diag_log format["R3F_FNCT_PointInShape %1",[_result, _center, _size, _corrected_angle, _dist, _cx, _cy]];
	_result;
};